﻿Imports System.Data.OleDb
Public Class Warning_Detail
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'The following code is needed to update comment list as soon as the user submits them.

        If Request.Params("ID") = "" Then
            Response.Redirect("Warnings_All.aspx")
        End If
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TravellingAloneConnectionString").ConnectionString)
        Dim SqlString As String = "SELECT * FROM warnings_comments WHERE warnings_fkid = @f1"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        oleDbConn.Open()
        Dim dataReader = cmd.ExecuteReader()
        GridView2.DataSource = dataReader
        GridView2.DataBind()


    End Sub

    Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_submit.Click

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TravellingAloneConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into warnings_comments(the_comment, warning_fkid) Values (@f1, @f2)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_comment.Text)
        cmd.Parameters.AddWithValue("@f2", Request.Params("ID"))
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("Default.aspx")


    End Sub
End Class